<?php
class caf extends controller{

	function caf()
	{
	 	parent::Controller();
		$this->load->helper('url');
		$this->load->helper('form');
		$this->load->model('caf_model');
	}
	
	function bc_details()
	{
		$this->load->helper('flexigrid');
		
		$displayform = '';
		$displayform .='<div id=dashboard ><span>Batch Card Details</span> <a href='.base_url().'/idea_home/dashboard ><img align=right src="'.base_url().'images/home.png" alt="home" /></a><img align=right src="'.base_url().'images/back.png" id="back"" alt="back" ONCLICK="history.go(-1)" /></div>';
		
		$displayform .= '<br/>';
				
		$displayform .= '<table id="flex1" style="display:none" border=0 align=left ></table>';
		
		$colModel['sl_num'] = array('Sl No',100,TRUE,'center',0);
		$colModel['batch_number'] = array('Batch Number',150,TRUE,'center',0);
		$colModel['batch_mobilenum'] = array('Phone Number',150,TRUE,'center',2);
		$colModel['activation_date'] = array('Activation Date',100,TRUE,'center',0);
		$colModel['received_date'] = array('Received Date',100,TRUE,'center',0);
    $colModel['caf_entry'] = array('Data Entry',100,TRUE,'center',0);
    $colModel['qc_check'] = array('Validation',100,TRUE,'center',0);
    
		$gridParams = array(
			'width' => 'auto',
			'height' => 400,
			'rp' => 15,
			'rpOptions' => '[10,20,30,40]',
			'pagestat' => 'Displaying:{from} to {to} of {total} items.',
			'blockOpacity' => 0.5,
			'title' => 'Batch Card Details to be processed',
			'showTableToggleBtn' => true
		);
		
		$grid_js = build_grid_js('flex1',site_url("/ajax/phonenum_list"),$colModel,'sl_num','asc',$gridParams);
		
		$data['js_grid'] = $grid_js;	
		$data = array('formdisplay'=>$displayform,'js_grid'=>$grid_js );	
		$this->template->add_css('css/flexigrid/flexigrid.css');
		$this->template->add_js('js/flexigride/jquery.pack.js');
		$this->template->add_js('js/flexigride/flexigrid.pack.js');
		
		//ends here....
		$this->template->write_view('header','header', $data, True);
		$this->template->write_view('content', 'other_general');
		$this->template->render();
		
		
	}
	
	function data_entry($mobile_num = 0)
	{
	  $sl_num = 0;
    $distributor_name = ' ';
    $mobile = 0;
    
	  if($mobile_num == 0)
    {
   
    }
    else
    {
      
      $result = $this->caf_model->fetch_batchdetails('IGPBR2010016540',$mobile_num);
      $val = $result->result_array();
      $sl_num = $val[0]['sl_num'];
      $distributor_name = $val[0]['distributor_name'];
      $mobile = $val[0]['batch_mobilenum'];
    }
	     
		$displayform = '';
		$displayform .='<div id=dashboard ><span>Data Entry</span> <a href='.base_url().'/idea_home/dashboard ><img align=right src="'.base_url().'images/home.png" alt="home" /></a><img align=right src="'.base_url().'images/back.png" id="back"" alt="back" ONCLICK="history.go(-1)" /></div>';
		$attr = array('id'=>'data_entry_form');
		$displayform .= form_open('caf/save_entry',$attr);
		$displayform .= '<div id=div_entry >';
		$displayform .= '<div id=caf_info><fieldset><legend>CAF Info</legend>';
		$displayform .= '<span id=batch><B>Batch No:</B> ';
		$displayform .= '<span id=batch_no style="color:#999999" >IGPBR2010016540</span></span>';
		$displayform .= '<input type=hidden name=batch_id />';
		//$displayform .= '<input type=hidden name=batch_num value='.$batch_details[0]['batch_number'].' />';
		$displayform .= '<span id=sl_no><b>SL No:</b><input type="text" name="sl_num" value='.$sl_num.' size="2" />';
		$displayform .= '</span>';
		$displayform .= '<span id=mobile><b>Mobil Num:</b>';
		$displayform .= '<input type=text name=mobile_num size=10 value="'.$mobile.'" disabled=disabled /></span>';
		//$displayform .= '<input type=hidden name=mobile_num size=10 value='.$batch_details[0]['batch_mobilenum'].' />';
		$displayform .= '<span id=caf_filled><b>CAF Filed On:</b>'; 
		$date_num = date("d-m-Y");
		$displayform .= '<input type=text name =filled_on_date id=filled_on_date size=10 value='.$date_num.' disabled=disabled /></span>';
		$displayform .= '</fieldset></div>';
		$displayform .= '<div id=personal1><fieldset><legend>Personal Details</legend>';
		$displayform .= '<table align=left width=100% >';
		$displayform .= '<tr><td colspan=6><span id=salutation> Salutation:';
		$displayform .= '&nbsp;&nbsp;<select name=salutation><option value=Mr> Mr.</option>';
		$displayform .= '<option value=Mrs>Mrs.</option>';
		$displayform .= '<option value=Ms>Ms.</option>';
		$displayform .= '<option value=Dr>Dr.</option>';
		$displayform .= '</select>';
		$displayform .= '</span>';
		$displayform .= '<span id=sex>Sex:';
		$displayform .= '<select name=sex><option value=M>M</option>';
		$displayform .= '<option value=F>F</option></select></span>';
		$displayform .= '<span id=dob>DOB:';
		$displayform .= '<input type=text name =dob id=idob size=10 class="datepicker" /></span></td>';
		$displayform .= '</tr>';
		$displayform .= '<tr><td align=right>';
		$displayform .= 'Customer Name:</td>';
		$displayform .= '<td colspan=5><input type=text name=customer_name id=cust_name value="only text and hypen is allowed" class=autobox size=45 /></td></tr>';
		$displayform .= '<tr>';
		$displayform .= '<td align=right>Father Name:</td>';
		$displayform .= '<td colspan=5><input type=text name=father_name value="only text and hypen is allowed" id=father_name class=autobox size=45 /></td></tr>';
		$displayform .= '<tr><td align=right>Nationality:</td>';
		$displayform .= '<td><select name=nationality><option value=Indian>Indian</option>';
		$displayform .= '<option value=Foreigner>Foreigner</option></select>';
		$displayform .= '</td>';
		$displayform .= '<td>&nbsp;&nbsp;</td>';
		$displayform .= '<td align=right>State:</td>';
		$displayform .= '<td align=left colspan=2><select name=state id=state_name >';
		$displayform .= '<option value=" ">Please select state</option>';
		$tate_name = $this->caf_model->fetch_state();
		foreach($tate_name ->result_array() as $row)
		{
			$displayform .= '<option value='.$row['state_id'].'>'.$row['state_name'].'</option>';
		}
		$displayform .= '</select>';
		$displayform .= '</td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td align=right>DND:</td>';
		$displayform .= '<td colspan=5 ><select name=dnd>';
		$displayform .= '<option value=No>NO</option>';
		$displayform .= '<option value=Yes>Yes</option>';
		$displayform .= '</select>';
		$displayform .= '&nbsp;&nbsp;&nbsp;&nbsp;';
		$displayform .= 'Telemarketing:';
		$displayform .= '<select name=telemarketing>';
		$displayform .= '<option value=No>NO</option>';
		$displayform .= '<option value=Yes>Yes</option>';
		$displayform .= '</select>';
		$displayform .= '</td>';
		$displayform .= '</tr>';
		$displayform .= '</table>';
		$displayform .= '</fieldset></div>';
		$displayform .= '<div id="personal2"><fieldset><legend>Personal Details</legend>';
		$displayform .= '<table align=left width=100%>';
		$displayform .= '<tr>';
		$displayform .= '<td align=right>POI Type:</td>';
		$displayform .= '<td><select name="poi_type1">';
		
		$poi_name = $this->caf_model->fetch_poi();
		
		foreach($poi_name ->result_array() as $row)
		{
			$displayform .= '<option value='.$row['poi_id'].'>'.$row['poi_desc'].'</option>';
		}
		
		
		
		$displayform .= '</select></td>';
		$displayform .= '<td>&nbsp;</td>';
		$displayform .= '<td align=right>POI Type:</td>';
		$displayform .= '<td><select name="poi_type2">';
		
		foreach($poi_name ->result_array() as $row)
		{
			$displayform .= '<option value='.$row['poi_id'].'>'.$row['poi_desc'].'</option>';
		}
		
		$displayform .= '</select></td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td align=right>POI Num:</td>';
		$displayform .= '<td><input type=text name=poi_num1 value="No Special Character, only alpha/numeric" id=poi_num1 class=autobox size=30 /></td>';
		$displayform .= '<td>&nbsp;</td>';
		$displayform .= '<td align=right>POI Num:</td>';
		$displayform .= '<td><input type=text name=poi_num2 id=poi_num2 value="No Special Character, only alpha/numeric" class=autobox size=30 /></td>';
		$displayform .= '</tr>';
		$displayform .= '</table>';
		$displayform .= '</fieldset></div>';
		$displayform .= '<div>';
		$displayform .= '<div id=doc_add>';
		$displayform .= '<fieldset><legend>Document Address</legend>';
		$displayform .= '<table align=left width=100% >';
    $displayform .='<tr>';
    $displayform .='<td>&nbsp;';
    $displayform .='</td>';
    $displayform .='<td>&nbsp;';
    $displayform .='</td>';
    $displayform .='</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td align=right>Address:</td>';
		$displayform .= '<td><input type=text name=doc_addr_num id=doc_addr_num size=20 value="Door No/Flat No/House No" class=autobox /></td>';
		$displayform .= '</tr>'; 
		$displayform .= '<tr>';
		$displayform .= '<td >&nbsp;</td><td align=left><input type=text name=doc_addr_cross id=doc_addr_cross value="Cross,Main Stage,Block"  class=autobox />';
		$displayform .= '</td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td align=right>State:</td>';
		$displayform .= '<td align=left ><select name=doc_state id=doc_state_name style="width:200px;" >';
		$displayform .= '<option value=" ">Please select state</option>';
		$tate_name = $this->caf_model->fetch_state();
		foreach($tate_name ->result_array() as $row)
		{
			$displayform .= '<option value='.$row['state_id'].'>'.$row['state_name'].'</option>';
		}
		$displayform .= '</select>';
		$displayform .= '</td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td align="right">City/District:</td><td>';
		$displayform .= '<span id=document_city><select name=doc_city_name id=doc_city >';
		
	
		$displayform .= '</select></span>';
		
		
		
		$displayform .= '</td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td align=right>Area:</td>';
		
		$displayform .= '<td>';
		$area_name = $this->caf_model->fetch_area();

		$displayform .= '<span id=span_doc_area> <select name="doc_area_name"  id="doc_area">';
							
		$displayform .= '</select></span>';
		
		$displayform .='&nbsp;Pincode:<span id="span_doc_pin"><input type=text name=doc_pincode id=doc_pin size=6/></span></td>';
		$displayform .= '</tr>';
		$displayform .= '</table>';
		$displayform .= '</fieldset>';
		$displayform .= '</div>';
		$displayform .= '<div id=alt_add>';
		$displayform .= '<fieldset><legend>Alternate Address</legend>';
		$displayform .= '<table align=left>';
		$displayform .='<tr>';
    $displayform .='<td colspan =2 >';
    $displayform .='<input name="same_loc_addr" type="checkbox" id="same_loc" /> &nbsp;';
    $displayform .='Local and Alternate Address as same';  
    $displayform .='</td>';
    $displayform .='</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td align=right>Address:</td>';
		$displayform .= '<td><input type=text name=alt_addr_num value="Door No/Flat No/House No" id=alt_num class=autobox /></td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td >&nbsp;</td><td align=left><input type=text name=alt_addr_cross id=alt_cross value="Cross,Main Stage,Block"  class=autobox />';
		$displayform .= '</td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td align=right>State:</td>';
		$displayform .= '<td align=left ><select name=alt_state id=alt_state_name style="width:200px;" >';
		$displayform .= '<option value=" ">Please select state</option>';
		$tate_name = $this->caf_model->fetch_state();
		foreach($tate_name ->result_array() as $row)
		{
			$displayform .= '<option value='.$row['state_id'].'>'.$row['state_name'].'</option>';
		}
		$displayform .= '</select>';
		$displayform .= '</td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td align=right>City/District:</td><td align=left><span id=alternate_city>';
		$displayform .= '<select name=alt_city_name  id=alt_city>';
		$displayform .= '<option value=" "></option>';
		//$displayform .= '<option value="">please select city</option>';
		$displayform .= '</select></span>';
		
		
		$displayform .= '</td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td align=right>Area:</td>';
		
		$displayform .= '<td>';
		$displayform .= '<span id=span_alt_area ><select name="alt_area_name" id=alt_area>';
		$displayform .= '<option value="">please select area</option>';
		
		$displayform .= '</select></span>';
		$displayform .= '&nbsp;Pincode:<span id=span_alt_pin><input type=text name=alt_pincode id=alt_pin size=6 /></span></td>';
		$displayform .= '</tr>';
		$displayform .= '</table>';
		$displayform .= '</fieldset>';
		$displayform .= '</div>';
		$displayform .= '</div>';
		$displayform .= '<div id=local_addr>';
		$displayform .= '<fieldset><legend>Local Refree Details</legend>';
		$displayform .= '<table align=left>';
		$displayform .= '<tr>';
		$displayform .= '<td align=right>Address:</td>';
		$displayform .= '<td><input type=text name=loc_addr_num value="Door No/Flat No/House No" id="loc_addr_num" class=autobox /></td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td >&nbsp;</td><td align=left><input type=text name=loc_addr_cross id="loc_addr_cross" value="Cross,Main Stage,Block"  class=autobox />';
		$displayform .= '</td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td align=right>State:</td>';
		$displayform .= '<td align=left ><select name=loc_state id=loc_state_name style="width:200px;" >';
		$displayform .= '<option value=" ">Please select state</option>';
		$tate_name = $this->caf_model->fetch_state();
		foreach($tate_name ->result_array() as $row)
		{
			$displayform .= '<option value='.$row['state_id'].'>'.$row['state_name'].'</option>';
		}
		$displayform .= '</select>';
		$displayform .= '</td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<tr>';
		$displayform .= '<td align=right>City/District:</td>';
		
		$displayform .= '<td><span id=span_refer_city>';
		$displayform .= '<select name=loc_city_name id=loc_city >';
		//$displayform .= '<option value="">please select city</option>';
		$displayform .= '</select></span>';
		
		$displayform .= '</td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td align=right>Area:</td><td align=left>';
		$displayform .= '<span id=span_loc_area ><select name="loc_area_name" id=loc_area>';
		
		
		$displayform .= '</select></span>';
		
		$displayform .=	'&nbsp;Pincode:<span id=span_loc_pin ><input type=text name=loc_pincode id="loc_pin" size=6/></span></td>';
		$displayform .= '</tr>';
		$displayform .= '</table>';
		$displayform .= '</fieldset>';
		$displayform .= '</div>';
		
		$displayform .= '<div id=instructions>';
		$displayform .= '<fieldset><legend style="color:blue;">Instructions:</legend>';
		$displayform .= '<table align=left width=100% >';
		$displayform .= '<tr>';
		$displayform .= '<td>&nbsp;&nbsp;</td><td > -No special character is allowed in any field</td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td>&nbsp;&nbsp;</td><td align=left>-Form filed date is validated for rejections';
		$displayform .= '</td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td>&nbsp;&nbsp;</td><td  align=left>-Date format is dd/mm/yyyy';
		$displayform .= '</td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td>&nbsp;&nbsp;</td><td align=left  > -xadf fjakfjakfjkadsfjkdsfjkl</td>';
		$displayform .= '</tr>';
		$displayform .= '<tr>';
		$displayform .= '<td colspan=2 align=center> <input type=submit id=submit_data value=Save "> &nbsp;&nbsp;<input type=reset value=Cancel "></td>';
		$displayform .= '</tr>';
		$displayform .= '</table>';
		$displayform .= '</fieldset>';
		$displayform .= '</div>';
		


		$displayform .= form_close();
		$displayform .= '</div>';
	
		$data = array('formdisplay'=>$displayform );

		
		
		$this->template->add_js('js/ui/jquery.ui.datepicker.js');
		$this->template->add_js('js/jquery.autobox.js');
		
		$this->template->add_js('js/ui/jquery.ui.position.js');
		$this->template->add_js('js/ui/jquery.ui.autocomplete.js');
		$this->template->add_js('js/caf/caf.js');
		
		$this->template->add_js('
				$(function() {
			$( ".datepicker" ).datepicker(			
			{
			dateFormat: "dd/mm/yy",
			yearRange: "1900:2010",
			changeMonth: true,
			changeYear: true,
			showOn: "button",
			buttonImage: "'.base_url().'images/calendar.gif",
			buttonImageOnly: true
		
		});
		
		});

		','embed');
	 
     
		$this->template->write_view('header','header', $data, True);
		$this->template->write_view('content', 'other_general');
		$this->template->render();
	}
	//to save data entered values....
	function save_entry()
	{
		
		$this->caf_model->data_entry_save();
		redirect("caf/bc_details");
	}
	
//to for ajax to display cities in document addresss...	
	function doc_display_cities($id=0)
	{
			
		$this->load->model('cities_model');
		$cities= $this->cities_model->disp_cities($id);
		$ajaxVal = '';
		$ajaxVal .= '<select name=doc_city_name id=doc_city >';
		$ajaxVal .= '<option value="" > </option>';
		foreach ($cities->result_array() as $row)
		{
			$ajaxVal .= '<option value="'.$row['city_id'].'">'.$row['city_name'].'</option>';
		}
		$ajaxVal .='</select>';
		
		echo $ajaxVal;
	}
//to for ajax to display areas in document addresss...		
	function doc_display_areas($id=0)
	{
		$this->load->model('area_model');
		$areas= $this->area_model->disp_areas($id);
		$ajaxVal = '';
		$ajaxVal .= '<select name=doc_area_name id=doc_area >';
		$ajaxVal .= '<option value="" > </option>';
		foreach ($areas->result_array() as $row)
		{
			$ajaxVal .= '<option value="'.$row['area_id'].'">'.$row['area_name'].'</option>';
		}
		$ajaxVal .='</select>';
		
		echo $ajaxVal;
	}
	
	//to display pincode in document field...
	function doc_display_pin($id=0)
	{
		$this->load->model('area_model');
		$pincode = $this->area_model->disp_pincode($id);
		$code = $pincode->result_array();
		$ajaxVal = '';
		if($id == 0)
		{
			$ajaxVal .= '<input type=text name=doc_pincode value=" " size=6 />';	
		}
		else
		{
		//$ajaxVal .= print_r($code);
		$ajaxVal .= '<input type=text name=doc_pincode value="'.$code[0]['area_pincode'].'" size=6 />';
		}
		
		echo $ajaxVal;
	}
	
	//to for ajax to display areas in alternate addresss...		
	function alt_display_areas($id=0)
	{
		$this->load->model('area_model');
		$areas= $this->area_model->disp_areas($id);
		$ajaxVal = '';
		$ajaxVal .= '<select name=alt_area_name id=alt_area >';
		$ajaxVal .= '<option value="" > </option>';
		foreach ($areas->result_array() as $row)
		{
			$ajaxVal .= '<option value="'.$row['area_id'].'">'.$row['area_name'].'</option>';
		}
		$ajaxVal .='</select>';
		
		echo $ajaxVal;
	}
	
	//to display pincode in alternate field...
	function alt_display_pin($id=0)
	{
		$this->load->model('area_model');
		$pincode = $this->area_model->disp_pincode($id);
		$code = $pincode->result_array();
		$ajaxVal = '';
		if($id == 0)
		{
			$ajaxVal .= '<input type=text name=alt_pincode id="alt_pin" value=" " size=6 />';	
		}
		else
		{
		//$ajaxVal .= print_r($code);
		$ajaxVal .= '<input type=text name=alt_pincode id="alt_pin" value="'.$code[0]['area_pincode'].'" size=6 />';
		}
		
		echo $ajaxVal;
	}
		
		function alt_display_cities($id=0)
	{
			
		$this->load->model('cities_model');
		$cities = $this->cities_model->disp_cities($id);
		$ajaxVal = '';
		$ajaxVal .= '<select name=alt_city_name id=alt_city>';
		$ajaxVal .= '<option value=" " ></option>';
		foreach ($cities->result_array() as $row)
		{
			$ajaxVal .= '<option value="'.$row['city_id'].'">'.$row['city_name'].'</option>';
		}
		$ajaxVal .='</select>';
		
		echo $ajaxVal;
	}

	
	function loc_display_cities($id=0)
	{
			
		$this->load->model('cities_model');
		$cities = $this->cities_model->disp_cities($id);
		$ajaxVal = '';
		$ajaxVal .= '<select name=loc_city id=loc_city >';
		$ajaxVal .= '<option value="" ></option>';
		foreach ($cities->result_array() as $row)
		{
			$ajaxVal .= '<option value="'.$row['city_id'].'">'.$row['city_name'].'</option>';
		}
		$ajaxVal .='</select>';
		
		echo $ajaxVal;
	}
	
	//to for ajax to display areas in local addresss...		
	function loc_display_areas($id=0)
	{
		$this->load->model('area_model');
		$areas= $this->area_model->disp_areas($id);
		$ajaxVal = '';
		$ajaxVal .= '<select name=loc_area_name id=loc_area >';
		$ajaxVal .= '<option value="" > </option>';
		foreach ($areas->result_array() as $row)
		{
			$ajaxVal .= '<option value="'.$row['area_id'].'">'.$row['area_name'].'</option>';
		}
		$ajaxVal .='</select>';
		
		echo $ajaxVal;
	}
	
	//to display pincode in local field...
	function loc_display_pin($id=0)
	{
		$this->load->model('area_model');
		$pincode = $this->area_model->disp_pincode($id);
		$code = $pincode->result_array();
		$ajaxVal = '';
		if($id == 0)
		{
			$ajaxVal .= '<input type=text name=loc_pincode value=" " size=6 />';	
		}
		else
		{
		//$ajaxVal .= print_r($code);
		$ajaxVal .= '<input type=text name=loc_pincode value="'.$code[0]['area_pincode'].'" size=6 />';
		}
		
		echo $ajaxVal;
	}
	

		
	
}

